package org.oslims.server.dao.hbm;

import java.util.List;

import org.hibernate.Query;
import org.oslims.domain.SampleType;
import org.oslims.server.dao.SampleTypeDao;

public class HbmSampleTypeDao extends HbmGenericDao<SampleType, Long> implements SampleTypeDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<SampleType> findAllWithAnalysis() {
		Query q = this.getSession().createQuery("select distinct s from SampleType s left join fetch s.possibleAnalysis order by s.name");
		return q.list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<SampleType> findAllWithAnalysis(int start, int length, String sortBy, Boolean desc) {

		String sortDirection = "asc";

		if (desc)
			sortDirection = "desc";

		Query q = this.getSession().createQuery("select distinct s from SampleType s left join fetch s.possibleAnalysis order by s." + sortBy + " " + sortDirection);
		q.setFirstResult(start);
		q.setMaxResults(length);

		return q.list();
	}

}
